﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Torch_Services
{
    public class MeetingRecordBll : IMeetingRecordBll
    {
        private IMeetingRecordDal _meet;
        private IMapper _mapper;
        public MeetingRecordBll(IMeetingRecordDal meet, IMapper mapper)
        {
            _meet = meet;
            _mapper = mapper;
        }

        public async Task<int> AddMeetingRecordAsync(int meetingTypeId, string meetingNoticeInfo, string JoinPerson, DateTime warnTime)
        {
            return await _meet.AddAsync(new Meetingrecord 
            {
                MeetingTypeId = meetingTypeId,
                MeetingNoticeInfo = meetingNoticeInfo,
                JoinPerson = JoinPerson,
                WarnTime = warnTime
            });
        }

        public async Task<int> DeleteMeetingRecordAsync(int id)
        {
            var data = await _meet.QueryAsync(id);
            return data == null ? -1 : await _meet.DeleteAsync(data);
        }

        public async Task<int> EditMeetingRecordAsync(int id, int meetingTypeId, string meetingNoticeInfo, string JoinPerson, DateTime warnTime)
        {
            var data = await _meet.QueryAsync(id);
            if (data == null)
                return -1;
            data.MeetingTypeId = meetingTypeId;
            data.MeetingNoticeInfo = meetingNoticeInfo;
            data.JoinPerson = JoinPerson;
            data.WarnTime = warnTime;
            return await _meet.EditAsync(data);
        }

        public async Task<List<MeetingRecordDto>> GetMeetingRecordAllAsync()
        {
            var data = await _meet.QueryAsync();
            return _mapper.Map<List<Meetingrecord>, List<MeetingRecordDto>>(data);
        }

        public async Task<MeetingRecordDto> QueryMeetingRecordByIdAsync(int id)
        {
            var data = await _meet.QueryAsync(id);
            return _mapper.Map<Meetingrecord, MeetingRecordDto>(data);
        }
    }
}
